import time

def read_from_file(filename):
    file = open(filename)
    data = file.readlines()
    data = list(map(int, data))
    return data

def bubble_sort(data):
    for i in range(len(data) - 1):
        swapped = False
        for j in range(len(data) - 1 - i):
            if data[j] > data[j + 1]:
                swapped = True
                data[j], data[j + 1] = data[j + 1], data[j]
        if not swapped:
            return
m1 = read_from_file("m1_sorted.txt")
t_start_m1 = time.time()
bubble_sort(m1)
t_finish_m1 = time.time()
time_m1 = round((t_finish_m1 - t_start_m1) * 1000)
print(f"m1_sorted {time_m1} milliseconds")


m2 = read_from_file("m2_reverse.txt")
t_start_m2 = time.time()
bubble_sort(m2)
t_finish_m2 = time.time()
time_m2 = round((t_finish_m2 - t_start_m2) * 1000)
print(f"m2_reverse {time_m2} milliseconds")

m3 = read_from_file("m3_shuffle.txt")
t_start_m3 = time.time()
bubble_sort(m3)
t_finish_m3 = time.time()
time_m3 = round((t_finish_m3 - t_start_m3) * 1000)
print(f"m3_shuffle {time_m3} milliseconds")
